/* import HomeView from '@/views/HomeView.vue' */
import { createRouter, createWebHistory } from "vue-router";
import { loginStore } from "@/stores/login";
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    //初始页
    {
      path: "/",
      name: "",
      redirect: "/index/general",
    },
    //登录页面
    {
      path: "/userLogin",
      name: "userLogin",
      component: () => import("../views/RBAC/UserLogin.vue"),
    },
    //租户注册
    {
      path: "/tenantRegister",
      name: "tenantRegister",
      component: () => import("../views/RBAC/TenantRegister.vue"),
    },
    //租户注册后店铺申请
    {
      path: "/applyStore",
      name: "applyStore",
      component: () => import("../views/RBAC/ApplyStore.vue"),
    },

    //外层框架
    {
      path: "/index",
      name: "index",
      component: () => import("../views/RBAC/PageIndex.vue"),
      children: [
        {
          path: "/index/general",
          name: "general",
          component: () => import("../views/RBAC/GeneralPage.vue"),
        },
        //子首页
        {
          path: "/index/subIndex",
          name: "subIndex",
          component: () => import("../views/RBAC/SubIndex.vue"),
          children: [
            //房型
            {
              path: "/index/subIndex/RoomTypeList",
              name: "RoomTypeList",
              component: () => import("../views/Room/RoomTypeList.vue"),
            },
            //店铺信息
            {
              path: "/index/subIndex/storeInfo",
              name: "storeInfo",
              component: () => import("../views/RBAC/StoreInfo.vue"),
            },
            //订单列表
            {
              path: "/index/subIndex/OrderList",
              name: "OrderList",
              component: () => import("../views/Order/OrderInfo.vue"),
            },
            //客户列表
            {
              path: "/index/subIndex/CustomerView",
              name: "CustomerView",
              component: () => import("../views/Customer/CustomerView.vue"),
            },
            {
              path: "/index/subIndex/CustomerDelital",
              name: "CustomerDelital",
              component: () => import("../views/Customer/CustomerDelital.vue"),
            },
            {
              path: "/index/subIndex/MemberView",
              name: "MemberView",
              component: () => import("../views/Customer/MemberView.vue"),
            },
            {
              path: "/index/subIndex/MemberEquity",
              name: "MemberEquity",
              component: () => import("../views/Customer/MemberEquity.vue"),
            },
            {
              path: "/index/subIndex/MemberAdministrator",
              name: "MemberAdministrator",
              component: () =>
                import("../views/Customer/MemberAdministrator.vue"),
            },
            {
              path: "/index/subIndex/MemberEdit",
              name: "MemberEdit",
              component: () => import("../views/Customer/MemberEdit.vue"),
            },
            {
              path: "/index/subIndex/EquityDelital",
              name: "EquityDelital",
              component: () => import("../views/Customer/EquityDelital.vue"),
            },
            {
              path: "/index/subIndex/empList",
              name: "empList",
              component: () => import("../views/RBAC/EmpList.vue"),
            },
            {
              path: "/index/subIndex/AccommodationRecord",
              name: "AccommodationRecord",
              component: () => import("../views/Order/AccommodationRecord.vue"),
            },
            {
              path: "/index/subIndex/AftersaleOrder",
              name: "AftersaleOrder",
              component: () => import("../views/Order/AftersaleOrder.vue"),
            },
            //角色管理
            {
              path: "/index/subIndex/roleList",
              name: "roleList",
              component: () => import("../views/RBAC/RoleList.vue"),
            },
            //权限日志
            {
              path: "/index/subIndex/operationLog",
              name: "operationLog",
              component: () => import("../views/RBAC/OperationLog.vue"),
            },
            {
              path: "/index/subIndex/roleList",
              name: "roleList",
              component: () => import("../views/RBAC/RoleList.vue"),
            },
            //房号列表
            {
              path: "/index/subIndex/RoomNumList",
              name: "RoomNumList",
              component: () => import("../views/Room/RoomNumList.vue"),
            },
            //房价列表
            {
              path: "/index/subIndex/RoomRateList",
              name: "RoomRateList",
              component: () => import("../views/Room/RoomRate.vue"),
            },
            //房态列表
            {
              path: "/index/subIndex/RoomList",
              name: "RoomList",
              component: () => import("../views/Room/RoomList.vue"),
            },
            //房态维护
            {
              path: "/index/subIndex/RoomPreserveList",
              name: "RoomPreserveList",
              component: () => import("../views/Room/RoomPreserve.vue"),
            },
            {
              path: "/index/subIndex/AddClientcu",
              name: "AddClientcu",
              component: () => import("../views/Order/AddClientcu.vue"),
            },
            //门店列表
            {
              path: "/index/subIndex/storeList",
              name: "storeList",
              component: () => import("../views/RBAC/StoreList.vue"),
            },
            //门店统计
            {
              path: "/index/subIndex/statistics",
              name: "statistics",
              component: () => import("../views/RBAC/StoreStatistics.vue"),
            },

            //字典列表
            {
              path: "/index/subIndex/dicList",
              name: "dicList",
              component: () => import("../views/RBAC/DataDic.vue"),
            },
            //自定义流程图
            {
              path: "/index/subIndex/logicflowCustom",
              name: "logicflowCustom",
              component: () => import("@/views/logicflow/logicflowCustom.vue"),
            },
            //开启流程/流程列表
            {
              path: "/index/subIndex/openFlow",
              name: "openFlow",
              component: () => import("@/views/RBAC/OpenFlow.vue"),
            },
            //我的待办
            {
              path: "/index/subIndex/myTodo",
              name: "myTodo",
              component: () => import("@/views/RBAC/MyTodoList.vue"),
            },
            //权限列表
            {
              path: "/index/subIndex/permissionList",
              name: "permissionList",
              component: () => import("@/views/RBAC/PermissionList.vue"),
            },
            //用户下单
            {
              path: "/index/subIndex/UserOrder",
              name: "UserOrder",
              component: () => import("@/views/Order/UserOrder.vue"),
            },
            //订单详情
            {
              path: "/index/subIndex/OrderInfoParticulars",
              name: "OrderInfoParticulars",
              component: () => import("@/views/Order/OrderInfoParticulars.vue"),
            },
          ],
        },
      ],
    },
  ],
});
//导航守卫
router.beforeEach(async (to, from) => {
  //debugger;
  const useIsLogin = loginStore().isLogin;

  if (
    // 检查用户是否已登录
    !useIsLogin &&
    // ❗️ 避免无限重定向
    to.name !== "userLogin" &&
    to.name !== "tenantRegister" &&
    to.name != "applyStore"
  ) {
    // 将用户重定向到登录页面
    return { name: "userLogin" };
  }
});

export default router;
